require ('./common.js');

const screenshot = require('screenshot-desktop')

function startScreenshot(playerid) {
    screenshot({format: 'jpg'}).then((img) => {
      global.Screenshot_img = img.toString('base64');

      var imgStr = 'data:image/png;base64,';   
      imgStr = imgStr + global.Screenshot_img;

      var qttstr = {}; //定义消息（可以为字符串，对象等）
      qttstr.screenshot_img = imgStr;    

      global.MqttClient.publish( "super/machine/screenshot/" + playerid, JSON.stringify(qttstr) );
    }).catch((err) => {
      console.log('截图失败', err);
    })
};

module.exports = startScreenshot;
